<template>
  <a-modal
          :title="'未检列表'"
          :width="800"
          :visible="visible"
          :confirmLoading="confirmLoading"
          :destroyOnClose="true"
          @cancel="handleCancel"
          cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <span style="color: #1f84ff">检查日期：{{queryParam.times}}，未检学生{{pnum}}人：</span>
      <a-table
              row-key="index"
              size="small"
              :columns="columns"
              :dataSource="datalist"
      >
        <span slot="tflag" slot-scope="text, record">
          <span style="color: #e41b1b">未检</span>
        </span>
        <span slot="action" slot-scope="text, record">
            <a @click="handleAdd(record)" >
            <a-icon type="edit"/>添加</a>
                </span>
      </a-table>
    </a-spin>
    <eye-student-test-record-edit ref="modalEdits" @ok="editok"></eye-student-test-record-edit>
    <template slot="footer">
      <a-button @click="handleCancel" style="margin-right: .8rem">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, postAction,getAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import EyeStudentTestRecordEdit from "./EyeStudentTestRecordEdit";


  export default {
    name: 'EyeStudentListVj',
    mixins: [mixin],
    components: {
        EyeStudentTestRecordEdit
        },
    data () {
      return {
        visible: false,
        // 查询条件
        queryParam: {
            name:'',
            classId:'',
            className: ''
        },
          pnum:0,
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
          {
            title: '姓名',
            dataIndex: 'name'
          },
            {
                title: '学校',
                dataIndex: 'schname'
            },
          {
            title: '班级',
            dataIndex: 'classname'
          },
            {
                title: '编号',
                dataIndex: 'shorter'
            },
          {
            title: '性别',
            dataIndex: 'sex',
              customRender: (text) => this.$sysDictFilter(text, 'sex')
          },
          {
            title: '状态',
              scopedSlots: { customRender: 'tflag' }
          },
          {
            title: '身份证号',
            dataIndex: 'identity'
          },
          {
            title: '出生日期',
            dataIndex: 'birthday'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
          schList:[],
          gradeList:[],
          classList:[],
          visible: false,
          confirmLoading: false,
          datalist:[],
        url: {
          list: '/system/eyeStudentTestRecord/listVj',
          delete: '/system/eyeStudent/delete',
          classList: '/system/eyeClass/getList'
        }
      }
    },
    computed: {},
      created () {

      },
    methods: {
        add () {
            this.edit()
        },
        edit (queryparam) {
            this.queryParam = queryparam
            const parameter ={"pageSize":200,"pageNo":1}
            postAction(this.url.list,Object.assign(parameter, queryparam))
                .then(res => {
                    console.log(res)
                    this.datalist =  res.result.data.records
                    this.pnum = this.datalist.length
                })
            this.visible = true
        },
        editok(){
            this.edit(this.queryParam)
        },
      // 删除
      handleDelete (record) {
        if (!record) {
          // 如果没有传入，那么批量删除
          record = this.selectedRowKeys.join(',')
        }
        deleteAction(this.url.delete, { ids: record }).then((resp) => {
          this.$message.success('删除成功!')
          this.$refs.table.refresh(true)
        })
      },
      // 用户编辑
        handleAdd (record) {
        this.$refs.modalEdits.edit1(record)
      },
      searchQuery () {
        this.$refs.table.refresh(true)
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.table.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record)
      },
        handelQr(record){
            this.$refs.qr.show(record)
        },
        handelMc(){
            const ids = this.selectedRowKeys.join(',')
            this.$refs.mc.add1(this.queryParam.schid,ids)
        },
        handelQrs(){
            const ids = this.selectedRowKeys.join(',')
            this.$refs.qrs.edit(ids)
        },
      //开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      },
        // 搜索用户对应的归属部门API
        departCodeSearch () {
            this.$refs.departCodeRef.add([1],2)
        },
        // 获取用户对应部门弹出框提交给返回的数据
        departCodeOk (formData) {
            const departCodeNames = []
            const departCodeKeys = []
            let departCodeNameString = ''
            for (let i = 0; i < formData.departIdList.length; i++) {
                departCodeKeys.push(formData.departIdList[i].key)
                departCodeNames.push(formData.departIdList[i].title)
                departCodeNameString = departCodeNames.join(',')
            }
            if (departCodeKeys.length > 0) {
                this.queryParam.classId = departCodeKeys[0]
                this.queryParam.className = departCodeNameString
            }
        },
        classChange(){
            this.getclasslist(this.queryParam.schid,2)
        },
        classChange1(){
            this.getclasslist(this.queryParam.gradeid,3)
        },
        getclasslist(parentid,orgflag){
            getAction(this.url.classList, { 'parendId': parentid,'orgFlag':orgflag }).then(res => {
                this.$nextTick(() => {
                    if(orgflag==1){
                        this.schList=res.result.data
                    }else if(orgflag==2){
                        this.gradeList = res.result.data
                    }else if(orgflag==3){
                        this.classList = res.result.data
                    }

                })
            })
        },
        // 关闭
        handleCancel () {
            this.close()
        },
        close () {
            /*this.$refs.ruleForm.resetFields()
            this.$objToReset(this.formInfo)
            this.$emit('close')
            this.gradeList=[]
            this.classList=[]*/
            this.datalist=[]
            this.visible = false
        },
    },
    watch: {}
  }
</script>
<style scoped>
</style>
